import * as dd from 'dingtalk-jsapi';
import * as setting from '@/config/setting.js'
import * as sCode from '@/config/statuxCode.js'

 
// corpId：Client ID (原 AppKey 和 SuiteKey)，从应用基本信息获取
export const getAuthCode = () => {
  return new Promise((resolve, reject) => {
    dd.getAuthCode({
      corpId: setting.corpId, 
      success:function(result){
		  console.log('钉钉SDK，获取code，请求成功的返回内容', result)
		  
		  for (let item in result) {
			  if (item === 'code') {
				  console.log(456, 'code', result.code)
				  var authCode = result.code
			  } else {
				  console.log(123, 'authCode', result.authCode)
				  var authCode = result.authCode
			  }
		  }
          
          uni.setStorageSync(setting.authCode, authCode)
          uni.setStorageSync(setting.authCodeMsg, sCode.code_200)
		  reject(sCode.code_200)
		  return
      },
      fail:function(err){
        // 获取授权码失败
        console.log('======= 获取授权码失败 =========',setting.corpId, err);
        uni.setStorageSync(setting.authCodeMsg, sCode.code_400)
        reject(sCode.code_400);
		return
      }
    });
  })
}


